package com.intellagric.controller.module.ift_scene;

import com.intellagric.common.pojo.LayuiDataGridResult;
import com.intellagric.common.pojo.ResponseMessage;
import com.intellagric.module.iftmonitor.SceneVo;
import com.intellagric.pojo.IftScene;
import com.intellagric.service.iftmonitor.ift_scene.SceneService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.Date;
import java.util.List;
import java.util.UUID;

/**
 * @Author: zhy
 * @email: 1269679946@qq.com
 * @Date: 2018/10/25
 * @DESC： 场景信息管理
 */
@Controller
public class SceneController {

    @Autowired
    private SceneService sceneService;

    /**
     * 添加场景信息
     * @Param
     * @return ResponseMessage
     */
    @RequestMapping("/scene/add")
    @ResponseBody
    public ResponseMessage add(IftScene scene) {
        //初始化参数
        scene.setId(UUID.randomUUID().toString().replaceAll("-",""));
        scene.setCreateDate(new Date());
        scene.setUpdateDate(new Date());
        return sceneService.addScene(scene);
    }

    /**
     * 删除场景信息
     * @Param id
     * @return ResponseMessage
     */
    @RequestMapping("/scene/delete")
    @ResponseBody
    public ResponseMessage delete(String id) {
        return sceneService.deleteScene(id);
    }

    /**
     * 修改场景信息
     * @Param
     * @return ResponseMessage
     */
    @RequestMapping("/scene/edit")
    @ResponseBody
    public ResponseMessage edit(IftScene scene) {
        scene.setCreateDate(null);
        scene.setUpdateDate(new Date());
        return sceneService.editScene(scene);
    }

    /**
     * 查询场景信息
     * @return IftScene
     */
    @RequestMapping("/scene/{id}")
    @ResponseBody
    public IftScene get(@PathVariable String id) {
        return sceneService.getSceneById(id);
    }

    /**
     * 多条件查询场景信息
     * @return IftScene
     */
    @RequestMapping("/scene/query")
    @ResponseBody
    public LayuiDataGridResult getByVo(SceneVo sceneVo) {
        return sceneService.getSceneByVo(sceneVo);
    }

    /**
     * 查询场景信息列表
     * @return LayuiDataGridResult
     */
    @RequestMapping("/scene/list")
    @ResponseBody
    public LayuiDataGridResult getList(String user) {
        if (user != null && !user.equals("1")) { //超级管理员
            return sceneService.getSceneTreeByUser(user);
        }
        return sceneService.getSceneList();
    }

    /**
     * 根据创建者查询场景信息列表
     * @return LayuiDataGridResult
     */
    @RequestMapping("/scene/tree/user")
    @ResponseBody
    public LayuiDataGridResult getTreeByUser(String createBy) {
        return sceneService.getSceneTreeByUser(createBy);
    }

    /**
     * 查询场景信息列表
     * @return LayuiDataGridResult
     */
    @RequestMapping("/scene/tree")
    @ResponseBody
    public LayuiDataGridResult getTree() {
        return sceneService.getSceneTree();
    }

    /**
     * 查询场景信息列表
     * @return LayuiDataGridResult
     */
    @RequestMapping("/scene/tree/select")
    @ResponseBody
    public List<IftScene> getTreeSelect() {
        return sceneService.getSceneTree().getData();
    }

    /**
     * 分页查询场景信息列表
     * @return LayuiDataGridResult
     */
    @RequestMapping("/scene/page")
    @ResponseBody
    public LayuiDataGridResult getPage(int page,int rows) {
        return sceneService.getScenePage(page,rows);
    }
}
